<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
      layout:decorate="main">
<head>
    <title>资源添加</title>
    <link th:href="@{/localcss/crmlist.css}" href="../static/localcss/crmadd.css" rel="stylesheet">
</head>
<body>
<div layout:fragment="content">
    <div class="">
    <div class="clearfix"></div>
    <div class="row">
        <div class="col-md-12 col-sm-12 col-xs-12">
            <div class="x_panel">
                <div class="x_title">
                    <h2>新增资源信息 <i class="fa fa-user"></i></h2>
                    <div class="clearfix"></div>
                </div>
                <div class="x_content">
                    <div class="clearfix"></div>
                    <form class="form-horizontal form-label-left" th:action="@{/right/save}" action="/right/save" method="post">
                        <div class="item form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="rightCode"> 资源编码 <span class="required">*</span>
                            </label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <input id="rightCode" class="form-control col-md-7 col-xs-12"
                                       data-validate-length-range="10" data-validate-words="1" name="rightCode" required="required"
                                       placeholder="请输入资源编码" type="text">
                            </div>
                        </div>
                        <div class="item form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="rightText"> 资源名称 <span class="required">*</span>
                            </label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <input id="rightText" class="form-control col-md-7 col-xs-12"
                                       data-validate-length-range="10" data-validate-words="1" name="rightText" required="required"
                                       placeholder="资源名称" type="text">
                            </div>
                        </div>
                        <div class="item form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12"> 资源类型 <span class="required">*</span></label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <input type="radio" name="rightType" value="Folder">一级菜单
                                <input type="radio" name="rightType" value="Document">二级菜单
                                <input type="radio" name="rightType" value="Button">按钮
                            </div>
                        </div>
                        <div class="item form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="rightParentCode"> 所属父资源 <span class="required">*</span></label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <select name="rightParentCode" id="rightParentCode" class="form-control">
                                    <option value="">--请选择--</option>
                                </select>
                            </div>
                        </div>
                        <div class="item form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="rightUrl"> 请求地址 <span class="required">*</span>
                            </label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <input id="rightUrl" class="form-control col-md-7 col-xs-12"
                                       data-validate-length-range="10" data-validate-words="1" name="rightUrl" required="required"
                                       placeholder="请求地址" type="text">
                            </div>
                        </div>
                        <div class="item form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="rightTip"> 备注 <span class="required">*</span>
                            </label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <input id="rightTip" class="form-control col-md-7 col-xs-12"
                                       data-validate-length-range="10" data-validate-words="1" name="rightTip" required="required"
                                       placeholder="备注" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-3">
                                <button id="send" type="submit" class="btn btn-success">保存</button>
                                <button type="button" class="btn btn-primary" id="back">返回</button>
                                <br/><br/>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
</body>
<script layout:fragment="js">
    $(document).ready(function(){
        $("#back").on("click",function(){
            window.history.back();
        });

        $("input[name=rightType]").change(function(){
            let rightType=$(this).val();
            if(rightType=="Folder"){
                var op=" <option value='ROOT_MENU'>--根菜单--</option>";
                $("#rightParentCode").html(op);
            }else {
                if(rightType=="Document"){
                    rightType="Folder";
                }else if(rightType=="Button"){
                    rightType="Document";
                }
                $("#rightParentCode option").remove();
                $.ajax({
                    type:"GET",
                    url:"/right/findAllRights",
                    dataType:"json",
                    data: "rightType=" + rightType,
                    success:function(data){
                        //获取model中roleId
                        for(var i in data){
                            var op="<option value='"+data[i].rightCode+"'>"+data[i].rightText+"</option>";
                            $("#rightParentCode").append(op);
                        }
                    },
                    error:function(data){
                        alert("对不起，获取数据失败！");
                    }
                });
            }
        });
    });
</script>
</html>